class UserSessionsController < ApplicationController
  before_filter :require_no_user, :only => [:new, :create]
  before_filter :require_user, :only => :destroy
  def new
    @user_session = UserSession.new
  end

  def create
    @user_session = UserSession.new(params[:user_session])
    if @user_session.save
      flash[:notice] = "登录成功！"
      redirect_back_or_default root_url
    else
      flash[:notice] = "用户名或密码错误！"
      render :action => :new, :layout => 'application'
    end
  end

  def destroy
    current_user_session.destroy
    flash[:notice] = "注销成功！"
    redirect_back_or_default root_url
  end

  private
  # => 清除右侧目录树片段的缓存
  #  def expire_fragment_cache
  #    expire_fragment(RecordSweeper::PATH.merge(:action_suffix => 'user_nav'))
  #  end
end
